package com.quanyan.ic.datacenter.http.service.impl;

import com.quanyan.ic.datacenter.dao.*;
import com.quanyan.ic.datacenter.http.req.ReqReport;
import com.quanyan.ic.datacenter.http.resp.RespAlarmsDayTable;
import com.quanyan.ic.datacenter.http.resp.RespAlarmsHandlePie;
import com.quanyan.ic.datacenter.http.resp.RespAlarmsTimePointLineChart;
import com.quanyan.ic.datacenter.http.service.AlarmsDayReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by jian.zhou on 2017/8/22.
 */
@Service
public class AlarmsDayReportServiceImpl implements AlarmsDayReportService {

    @Autowired
    private IcCityAlarmsDayReportDao icCityAlarmsDayReportDao;

    @Autowired
    private IcPlaceAlarmsDayReportDao icPlaceAlarmsDayReportDao;

    @Autowired
    private AlarmTimePointReportOfCityDao alarmTimePointReportOfCityDao;

    @Autowired
    private AlarmTimePointReportOfPlaceDao alarmTimePointReportOfPlaceDao;

    @Autowired
    private AlarmsHandelReportCityDao alarmsHandelReportCityDao;

    @Autowired
    private AlarmsHandelReportPlaceDao alarmsHandelReportPlaceDao;

    @Autowired
    private AlarmDayReportOfCityDao alarmDayReportOfCityDao;

    @Autowired
    private AlarmDayReportOfPlaceDao alarmDayReportOfPlaceDao;


    @Override
    public List<RespAlarmsDayTable> allAlarmsTable(ReqReport reqReport) {
        if (reqReport.getCityId() == 0)
            return icCityAlarmsDayReportDao.findCityDayReport(reqReport);
        else
            return icPlaceAlarmsDayReportDao.findPlaceDayReport(reqReport);
    }


    @Override
    public List<RespAlarmsTimePointLineChart> cityTimePointLineChart(ReqReport reqReport) {
        if (reqReport.getCityId() == 0){
            if ( reqReport.getStartDateStr().equals(reqReport.getEndDateStr()))
              return alarmTimePointReportOfCityDao.findAlarmTimePointReportOfCityByDay(reqReport);
            else
              return alarmDayReportOfCityDao.findAlarmDayReportCity(reqReport);
        }
        else{
            if ( reqReport.getStartDateStr().equals(reqReport.getEndDateStr()))
                return alarmTimePointReportOfPlaceDao.findAlarmTimePointReportOfPlaceByDay(reqReport);
            else
                return alarmDayReportOfPlaceDao.findAlarmDayReportPlace(reqReport);
        }
    }


    @Override
    public List<RespAlarmsHandlePie> alarmsHandlePieList(ReqReport reqReport){
        if (reqReport.getCityId() == 0)
            return alarmsHandelReportCityDao.findAlarmsHandleCityPie(reqReport);
        else
            return alarmsHandelReportPlaceDao.findAlarmsHandleCityPie(reqReport);
    }

    public List<RespAlarmsTimePointLineChart> cityTimePointLineChartPie(ReqReport reqReport) {
        List<RespAlarmsTimePointLineChart> lineChartList = this.cityTimePointLineChart(reqReport);
        List<RespAlarmsHandlePie> pieList = this.alarmsHandlePieList(reqReport);

        for (RespAlarmsHandlePie pie : pieList){
            for (RespAlarmsTimePointLineChart line : lineChartList){
                if (line.getId().intValue() == pie.getId()){
                    line.getPieList().add(pie);
                }
            }
        }
        return lineChartList;
    }


}
